<template>
	<view class="cars-info">
		<view v-if="newsList != ''">
			<view class="list" v-for="(item,index) in newsList" :key="index">
				<view class="onlist">
					<view class="onlist_left">
						<view class="onlist_l_l">
						</view>
						<view class="onlist_l_r">
							{{item.plate_no}}
						</view>
					</view>
					<view class="onlist_right">
						<view class="onlist_r_l" @click="onpark(item,index)">
							<image style="width: 20rpx;height: 20rpx;" src="https://oss.szsportscenter.cn/img/del.png"
								mode="">
							</image>
							<text style="margin-left: 10rpx;">绑定</text>
						</view>
						<view class="onlist_r_r" @click="ondel(item,index)">
							<image style="width: 20rpx;height: 20rpx;" src="https://oss.szsportscenter.cn/img/del1.png"
								mode="">
							</image>
							<text style="margin-left: 10rpx;">删除</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view v-else style="padding-top: 50rpx;">
			<u-empty text="暂无数据" :icon="icon3" />
		</view>
		<view class="bottom-add-btn">
			<u-button text="添加车辆" shape="circle" @click="add"
				color="linear-gradient(270deg, #2f75fa 0%, #5e9afa 100%, #99c3fa 0%)"></u-button>
		</view>
	</view>
</template>

<script>
	const index = require("@/api/index/index.js");
	export default {
		data() {
			return {
				newsList: [],
				icon3: this.$https.assetsPath + '58d1bf2665b8c20e302f02c56274f0ce972df8b4.png',
			}
		},
		onShow() {
			this.platelist()
		},
		methods: {
			onpark(item, index) {
				// uni.navigateTo({
				// 	url:'./cars_parking?item='+ encodeURIComponent(JSON.stringify(item))
				// })
				// uni.navigateTo({
				// 	url:'/pages_a/coupons/coupons'
				// })
				uni.navigateBack()
			},
			ondel(item, index) {
				let that = this
				uni.showModal({
					title: '删除',
					content: '是否确定删除！',
					success: function(res) {
						if (res.confirm) {
							that.dellist(item)
						}
					}
				});
			},
			dellist(item) {
				let params = {
					open_id: uni.getStorageSync('openid'),
					id: item.id
				};
				index.platedel(params).then(result => {
					if (result.code == 1) {
						uni.showToast({
							title: result.info,
							icon: 'success',
							mask: true
						})
						this.platelist()
					}
				})
			},
			async platelist() {
				let that = this
				let data = {
					open_id: uni.getStorageSync('openid'),
				}
				let result = await index.platelist(data)
				if (result.code == 1) {
					that.newsList = result.data.result
				}
			},
			add() {
				uni.navigateTo({
					url: './add/add_coupons'
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.cars-info {
		min-height: 100vh;
		width: 100%;
		background-color: #EDF5F5;

		.list {
			display: flex;
			flex-direction: row;
			justify-content: center;

			.onlist {
				width: 90%;
				height: 120rpx;
				background-color: #fff;
				border-radius: 20rpx;
				padding: 20rpx 20rpx;
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				margin-top: 20rpx;

				.onlist_left {
					display: flex;
					flex-direction: row;
					align-items: center;

					.onlist_l_l {
						width: 25rpx;
						height: 25rpx;
						background: linear-gradient(270deg, #2f75fa 0%, #5e9afa 100%, #99c3fa 0%);
						border-radius: 10rpx;
						margin-left: 20rpx;
					}

					.onlist_l_r {
						margin-left: 10rpx;
					}
				}

				.onlist_right {
					display: flex;
					flex-direction: row;
					align-items: center;
					font-size: 24rpx;
					color: #fff;

					.onlist_r_l {
						padding: 10rpx 20rpx;
						border-radius: 20rpx;
						background: linear-gradient(270deg, #2f75fa 0%, #5e9afa 100%, #99c3fa 0%);
						margin-right: 20rpx;
					}

					.onlist_r_r {
						padding: 10rpx 20rpx;
						border-radius: 20rpx;
						background: linear-gradient(270deg, #2f75fa 0%, #5e9afa 100%, #99c3fa 0%);
					}
				}
			}
		}

		.bottom-add-btn {
			position: fixed;
			width: 100%;
			height: 10vh;
			left: 0;
			bottom: 0;
			padding: 20rpx 30rpx;
			background-color: white;
		}
	}
</style>